package site.ruyi.devclient.core;

import java.io.File;

import org.sqlite.SQLiteDataSource;

import site.ruyi.devclient.util.DBUtil;

public class UserData {

	private static final String APP_DATA_DIR=".dev-client";

	private UserData(){}

	private static DBUtil DB_INSTANCE=null;
	public static DBUtil getDB(){
		if(DB_INSTANCE!=null){
			return DB_INSTANCE;
		}

		File appDataDir=new File(System.getProperty("user.home"),APP_DATA_DIR);
		if(!appDataDir.exists()){
			appDataDir.mkdir();
		}

		String dbFile=(new File(appDataDir,"app.db")).getAbsolutePath();

		SQLiteDataSource sds=new SQLiteDataSource();
		sds.setUrl("jdbc:sqlite:"+dbFile);
		DB_INSTANCE=DBUtil.getInstance(sds);
		return DB_INSTANCE;
	}
}
